package com.just.springbootsecurity.controller;

import com.just.springbootsecurity.dao.SysUserRepository;
import com.just.springbootsecurity.domain.Msg;
import com.just.springbootsecurity.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HomeController {
    @Autowired
    private SysUserRepository sysUserRepository;
    @RequestMapping("/")
    public String index(Model model){
        Msg msg=new Msg("测试标题","测试内容","额外信息，只对管理员显示");
        model.addAttribute("msg",msg);
        return "home";
    }
    @Transactional
    @PostMapping("/add")
    @ResponseBody
    public Object addUser(@RequestBody SysUser sysUser){
        sysUserRepository.save(sysUser);
        return sysUser;
    }
}
